Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alzheimer’s Disease Classification Using Vision Transformers (ViT) #182

Open
wants to merge 62 commits into
base: topic-recognition
Choose a base branch
from

Conversation

yttrium400
Copy link

@yttrium400 yttrium400 commented Oct 31, 2024

Purpose

This pull request introduces a Vision Transformer (ViT) model designed for the classification of Alzheimer’s Disease using MRI scans from the ADNI dataset. The model leverages the self-attention mechanism inherent to Transformers to extract meaningful features across different regions of the brain, aiming to differentiate between 'Normal' and 'Alzheimer’s Disease' categories.

Description

Task Chosen: Implement a ViT-based classifier for Alzheimer’s Disease detection using MRI data from the ADNI dataset. The target was to achieve a balanced performance on the test set and to explore the effectiveness of Transformer models in medical imaging analysis.

Model: The implemented Vision Transformer model divides each input MRI image into non-overlapping patches, linearly embeds these patches, and processes them through a series of self-attention layers to learn spatial dependencies. The final output is passed through a classification head that predicts whether a given MRI scan indicates 'Normal' or 'Alzheimer’s Disease'.

Performance: The best model configuration achieved a training accuracy of 67.78%, validation accuracy of 69.66% and test accuracy of 68.20%. The training process included early stopping to avoid overfitting and a detailed analysis of the training and validation metrics.

Dataset Preparation (dataset.py):

  • This module defines a custom PyTorch DataLoader that handles the ADNI dataset, resizing images to 224x224 pixels, applying data augmentation, and normalizing pixel values. The dataset is organized into 'train' and 'test' folders, and additional splitting ensures that the training data is further divided into training and validation sets.
  • The transformations include random horizontal and vertical flips, sharpness adjustment, and cropping to improve model generalization.

Network Modules (modules.py):

  • The Vision Transformer is implemented with a patch embedding layer, positional encoding, multiple Transformer blocks, and a final classification head. The architecture has been modified to suit grayscale MRI images, with appropriate configurations for embedding dimensions and self-attention layers.

Training Script (train.py):

  • This script outlines the full training pipeline for the Vision Transformer model. It includes the definition of the optimizer (Adam), learning rate scheduler (StepLR), and training and validation loops. The script also incorporates early stopping to enhance model performance and saves the best model based on validation accuracy.

Testing Script (predict.py):

  • This script loads the trained Vision Transformer model and evaluates it on the test dataset. It calculates accuracy, generates a confusion matrix, and saves performance plots. The script highlights key metrics and provides visualizations to aid in assessing model performance.

Performance and Visualizations:

  • The model achieved a training accuracy of 67.78%, validation accuracy of 69.66% and test accuracy of 68.20%, with training and validation plots generated to illustrate the learning progress.
  • The confusion matrix reveals areas where the model struggled, particularly in identifying false negatives, suggesting potential areas for improvement.

Request:

Kindly review the changes implemented in this pull request. If you find the modifications suitable, consider merging the request. Your feedback on possible improvements or further adjustments would be highly valued.

Thank You
Swastik Lohchab
47415056

@gayanku gayanku added the _ViT ViT (not using GFNet) label Nov 1, 2024
@shaivikaaaa
Copy link
Collaborator

This is an initial inspection

Difficulty : Hard
Task : 5

Recognition Problem:
The code structure looks ok
file structure good
model trained for 10 epochs only ?
testing accuracy is of 68.20%, minimum required is 80%
comments are ok - can be more detailed
more train and test images should be there

Commit Log:
Commit messages are ok
All commits are finished within 2 days

Documentation:
Requirement:

Title: Done
Description of the algorithm: Done
Problem that it solves: Done
How it works in a paragraph (example any pre-processing): Done
Figure/visualisation (any input, output & results): Done
Dependencies: Done

Pull Request
good

Feedback:
Add test and validation accuracy % in your PR and README file
ReadME has epochs to be 11 but epochs ran are 10 - update that

@aniketgupta17
Copy link
Collaborator

Observational Feedback

Pull Request:
Correctly created the Pull request from Topic Recognition Branch .
The pull request includes a clear description about the file structure .
No previous feedback incorporated.

File Organizing: Well-organized files.

Commit Log:
Commit messages are progressive for the Recognition Problem solved using 4 files .
Commits demonstrate logical development flow.

Documentation:
The README design looks good .
Code comments are included. Missing Docstrings for some fucntions .
Proper GitHub markdown formatting is used, with organized headings, lists, and code blocks.

@yttrium400
Copy link
Author

Thank You for the feedback! I added Docstrings and changed README file as well as Pull Request accordingly.

@hanemma7moud hanemma7moud added the PDF PDF submitted label Nov 13, 2024
@gayanku gayanku added the _After cutoff After Oct 28th label Nov 13, 2024
@gayanku
Copy link
Collaborator

gayanku commented Nov 14, 2024

Marking

Good/OK/Fair Practice (Design/Commenting, TF/Torch Usage)
Good design and implementation.
Spacing and comments.
No Header blocks. -1
Recognition Problem
OK solution to problem. Accuracy low.-2
Driver Script present.
File structure present.
Good Usage & Demo & Visualisation & Data usage.
Module present.
Commenting present.
No Data leakage found.
Difficulty : Hard. ViT (Hard Difficulty)
Commit Log
Good Meaningful commit messages.
Some/Adequate Progressive commits. Within 2 days.-1
Documentation
Readme :Good.
Model/technical explanation :Good.
Description and Comments :Good.
Markdown used and PDF submitted. PDF checked.
Pull Request
Pull Request has problems: Late submission.-2
No Feedback required.
Request Description is good.
TOTAL-6

Marked as per the due date and changes after which aren't necessarily allowed to contribute to grade for fairness.
Subject to approval from Shakes

@gayanku gayanku added the Preliminary Grade To be confirmed after review. label Nov 14, 2024
@yttrium400
Copy link
Author

Hi Gayan, thanks for marking my work. Just to highlight that I had an approved extension till 01/11/24 for the report.

Kind Regards,
Swastik Lohchab

@shakes76
Copy link
Owner

Approved extension +2

Cant merge because of conflicting changes to main repo files (README). Please update for merge, doesn't affect grade.

@shakes76 shakes76 added Completed Updated_Grade BB grade needs adjustment labels Nov 19, 2024
@yttrium400
Copy link
Author

Hi Shakes, thanks for your feedback. I've resolved the issues you highlighted.

Regards,
Swastik Lohchab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
_After cutoff After Oct 28th BB Completed PDF PDF submitted Preliminary Grade To be confirmed after review. Updated_Grade BB grade needs adjustment _ViT ViT (not using GFNet)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants